<template>
	<el-breadcrumb separator="/">
		<el-breadcrumb-item :to="{ path: '/' }">主页</el-breadcrumb-item>
		<el-breadcrumb-item v-for="(item, index) in breadcrumb" :key="index">
			{{item}}
		</el-breadcrumb-item>
	</el-breadcrumb>
</template>

<script>
	export default {
		data () {
			return {
				breadcrumb: []
			}
		},
		watch: {
			$route: function(to, from) {
				this.getBreadcrumb(to);
			}
		},
		created() {
			this.getBreadcrumb(this.$route);
		},
		methods: {
			// 获取面包屑信息
			getBreadcrumb(to) {
				this.breadcrumb = []; //置空
				if (to.meta.title !== '主页') {
					if (to.meta.isTopMenu) {
						this.breadcrumb.push(to.meta.title);
					} else {
						this.breadcrumb.push(to.matched[1].meta.title);
						this.breadcrumb.push(to.meta.title);
					}
				}
			}
		}
	}
</script>

<style>
	.el-breadcrumb {
		background-color: #fafafa;
		padding: 15px;
		padding-left: 20px;
	}
	.el-breadcrumb span {
		color: #464646;
		font-style: italic;
	}
</style>